﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGSVR.Common;
using System.Data;
using LGSVR.BLL.Sys;

namespace LGSVR_WEB.program
{
    public partial class MessageTimes : DataBasePage
    {
        private int Pid
        {
            get
            {
                return string.IsNullOrEmpty(Request.QueryString["ID"]) ? 0 : int.Parse(Request.QueryString["ID"]);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "out", "<script>alert('系统超时或服务器故障，请退出重新登录！');window.parent.parent.navigate('../Logout.aspx');</script>");
            }
            if (Pid != 0)
            {
                  MsgContent = ShowMessage("未选中节目信息，请重选", MessageType.Error, false, true);
            }
            if (!IsPostBack)
            {
                PageInit();
            }
        }

        void PageInit()
        {
       

            Dictionary<string, string> dicSingle;
          
               
            dicSingle = GetSigle("messageTimes", "messageID=" + Pid);

            if (dicSingle != null)
            {
                lblmessageID.Text = Request.QueryString["ID"];
                txttimeBegin.Value = dicSingle["timeBegin"];
                txtEndTime.Value = dicSingle["EndTime"];
                chkstate.Checked = Utils.ToBool(dicSingle["state"]);
                txtcontent.Text = dicSingle["content"];                     
            }
            else
            {
                MsgContent = ShowMessage("数据加载失败。", MessageType.Error, true, false);
            }
        }

              
            
        

        protected void btnSave_Click(object sender, EventArgs e)
        {            
            Dictionary<string, string> dicParam;
           
                dicParam = new Dictionary<string, string>();

                dicParam.Add("timeBegin", txttimeBegin.Value);
                dicParam.Add("EndTime", txtEndTime.Value);
                dicParam.Add("state", chkstate.Checked?"1":"0");
                dicParam.Add("content", txtcontent.Text.Trim());
                      
                   
                    Edit("messageGroup", dicParam, "messageID=" + Pid);

                        if (Result > 0)
                        {
                            MsgContent = ShowMessage("恭喜您，更新成功！", MessageType.Success, false, true);
                            NoRefresh();
                        }
                        else
                        {
                            if (Result == -100)
                            {
                                MsgContent = ShowMessage("对不起，操作失败，程序参数异常。", MessageType.Error, false, true);
                            }
                            else
                            {
                                MsgContent = ShowMessage("对不起,操作失败，请重试。", MessageType.Error, false, true);
                            }
                        }
                   
                }
                
            }
       

        //protected void btnBack_Click(object sender, EventArgs e)
        //{
        //    if (!string.IsNullOrEmpty(Request.QueryString["backUrlParam"]))
        //    {
        //        Response.Redirect("messageGroupList.aspx?" + Request.QueryString["backUrlParam"], false);
        //    }
        //    else
        //    {
        //        Response.Redirect("messageGroupList.aspx", false);
        //    }
        //}
  
}